package ooday04;

import java.util.Timer;
import java.util.TimerTask;

//匿名内部类练习----定时器
public class TimerDemo {

    public static void main(String[] args) {
        Timer timer = new Timer();
        timer.schedule(packUp(() -> System.out.println("定时器运行了")), 1000, 1000);
    }
//将timetsak强转成runnable功能性接口,可使用lambda表达式简化
    private static TimerTask packUp(Runnable r) {
        return new TimerTask() {
            @Override
            public void run() {
                r.run();
            }
        };
    }




/*        Timer timer = new Timer();
        int interval = 1000;
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("定时器响了");
            }
        }, interval, interval);*/
}